﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

namespace Team6_Algorithms.Filters
{
    /// <summary>
    /// Useless Class
    /// Made by Dylan Snel
    /// Class was used to maken an image black because some ither algorithm did it wrong.
    /// </summary>
    class BlackenAlgorithm
    {
        /// <summary>
        /// Makes the source image black;
        /// </summary>
        /// <param name="sourceImage"></param>
        /// <returns></returns>
        public static Bitmap applyFilter(Bitmap sourceImage)
        {
            
            Rectangle rect = new Rectangle(0, 0, sourceImage.Width, sourceImage.Height);
            Bitmap returnImage = (Bitmap) sourceImage.Clone();
            BitmapData srcData = returnImage.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

            int stride = srcData.Stride;
            int nOffset = stride - sourceImage.Width * 3;
            System.IntPtr Scan0 = srcData.Scan0;

            unsafe
            {
                byte* p = (byte*)(void*)Scan0;
                for (int y = 0; y < sourceImage.Height; ++y)
                {
                    for (int x = 0; x < sourceImage.Width; ++x)
                    {

                        p[0] = (byte) 0;
                        p[1] = (byte) 0;
                        p[2] = (byte) 0;

                        p += 3;
                                                
                    }                  
                    p += nOffset;
                  
                }
            }
            returnImage.UnlockBits(srcData);
            return returnImage;
        }
    }
}